package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_invoice_send;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_invoice_sendSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_invoice_sendService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[发送会计发票] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_invoice_sendServiceImpl implements IAccount_invoice_sendService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_invoice_sendClientService account_invoice_sendClientService;

    @Override
    public Account_invoice_send get(Integer id) {
        Iaccount_invoice_send clientModel = account_invoice_sendClientService.createModel();
        clientModel.setId(id);
        account_invoice_sendClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_invoice_send get(Account_invoice_send account_invoice_send) {
        Account_invoice_send retaccount_invoice_send = this.get(account_invoice_send.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_invoice_send.getClass(), account_invoice_send.getClass(), false);
        copier.copy(retaccount_invoice_send, account_invoice_send, null);
        return account_invoice_send ;
    }

    @Override
    public void updateBatch(List<Account_invoice_send> account_invoice_sends, int batchSize) {

        //account_invoice_sendClientService.updateBatch(account_invoice_sends,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_invoice_sendClientService.removeBatch(account_invoice_sends) ;

    }

    @Override
    public void createBatch(List<Account_invoice_send> account_invoice_sends, int batchSize) {

                        //account_invoice_sendClientService.createBatch(account_invoice_sends,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_invoice_send clientModel = account_invoice_sendClientService.createModel();
        clientModel.setId(id);
        account_invoice_sendClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean update(Account_invoice_send account_invoice_send) {
        boolean bOk = false ;
        Iaccount_invoice_send clientModel = this.convert2Model(account_invoice_send,null);
        account_invoice_sendClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_invoice_send) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean create(Account_invoice_send account_invoice_send) {
        boolean bOk = false ;
        Iaccount_invoice_send clientModel = this.convert2Model(account_invoice_send,null);
        account_invoice_sendClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_invoice_send);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_invoice_send> searchDefault(Account_invoice_sendSearchContext context) {
        List<Account_invoice_send> list = new ArrayList<Account_invoice_send>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send> clientModelList = account_invoice_sendClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_send>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据邮件撰写向导查询
     */
    @Override
    public Page<Account_invoice_send> selectByOdoo_composer(Integer id){
        Account_invoice_sendSearchContext context = new Account_invoice_sendSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_send> list = new ArrayList<Account_invoice_send>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send> clientModelList = account_invoice_sendClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_send>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据EMail模板查询
     */
    @Override
    public Page<Account_invoice_send> selectByOdoo_template(Integer id){
        Account_invoice_sendSearchContext context = new Account_invoice_sendSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_send> list = new ArrayList<Account_invoice_send>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send> clientModelList = account_invoice_sendClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_send>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_invoice_send> selectByOdoo_create(Integer id){
        Account_invoice_sendSearchContext context = new Account_invoice_sendSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_send> list = new ArrayList<Account_invoice_send>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send> clientModelList = account_invoice_sendClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_send>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Account_invoice_send> selectByOdoo_write(Integer id){
        Account_invoice_sendSearchContext context = new Account_invoice_sendSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Account_invoice_send> list = new ArrayList<Account_invoice_send>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send> clientModelList = account_invoice_sendClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_invoice_send clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_invoice_send>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Iaccount_invoice_send convert2Model(Account_invoice_send domain , Iaccount_invoice_send model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_invoice_sendClientService.createModel() ;
        }

         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getRating_idsDirtyFlag())
            model.setRating_ids(domain.getRating_ids());
         if(domain.getTracking_value_idsDirtyFlag())
            model.setTracking_value_ids(domain.getTracking_value_ids());
         if(domain.getCurrency_idDirtyFlag())
            model.setCurrency_id(domain.getCurrency_id());
         if(domain.getMailing_list_idsDirtyFlag())
            model.setMailing_list_ids(domain.getMailing_list_ids());
         if(domain.getPrintedDirtyFlag())
            model.setPrinted(domain.getPrinted());
         if(domain.getAttachment_idsDirtyFlag())
            model.setAttachment_ids(domain.getAttachment_ids());
         if(domain.getInvoice_without_emailDirtyFlag())
            model.setInvoice_without_email(domain.getInvoice_without_email());
         if(domain.getNeedaction_partner_idsDirtyFlag())
            model.setNeedaction_partner_ids(domain.getNeedaction_partner_ids());
         if(domain.getSnailmail_is_letterDirtyFlag())
            model.setSnailmail_is_letter(domain.getSnailmail_is_letter());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getIs_printDirtyFlag())
            model.setIs_print(domain.getIs_print());
         if(domain.getPartner_idDirtyFlag())
            model.setPartner_id(domain.getPartner_id());
         if(domain.getSnailmail_costDirtyFlag())
            model.setSnailmail_cost(domain.getSnailmail_cost());
         if(domain.getChannel_idsDirtyFlag())
            model.setChannel_ids(domain.getChannel_ids());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getStarred_partner_idsDirtyFlag())
            model.setStarred_partner_ids(domain.getStarred_partner_ids());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getPartner_idsDirtyFlag())
            model.setPartner_ids(domain.getPartner_ids());
         if(domain.getChild_idsDirtyFlag())
            model.setChild_ids(domain.getChild_ids());
         if(domain.getLetter_idsDirtyFlag())
            model.setLetter_ids(domain.getLetter_ids());
         if(domain.getNotification_idsDirtyFlag())
            model.setNotification_ids(domain.getNotification_ids());
         if(domain.getInvoice_idsDirtyFlag())
            model.setInvoice_ids(domain.getInvoice_ids());
         if(domain.getIs_emailDirtyFlag())
            model.setIs_email(domain.getIs_email());
         if(domain.getParent_idDirtyFlag())
            model.setParent_id(domain.getParent_id());
         if(domain.getUse_active_domainDirtyFlag())
            model.setUse_active_domain(domain.getUse_active_domain());
         if(domain.getModeration_statusDirtyFlag())
            model.setModeration_status(domain.getModeration_status());
         if(domain.getModerator_idDirtyFlag())
            model.setModerator_id(domain.getModerator_id());
         if(domain.getHas_errorDirtyFlag())
            model.setHas_error(domain.getHas_error());
         if(domain.getActive_domainDirtyFlag())
            model.setActive_domain(domain.getActive_domain());
         if(domain.getDescriptionDirtyFlag())
            model.setDescription(domain.getDescription());
         if(domain.getNo_auto_threadDirtyFlag())
            model.setNo_auto_thread(domain.getNo_auto_thread());
         if(domain.getComposition_modeDirtyFlag())
            model.setComposition_mode(domain.getComposition_mode());
         if(domain.getAdd_signDirtyFlag())
            model.setAdd_sign(domain.getAdd_sign());
         if(domain.getEmail_fromDirtyFlag())
            model.setEmail_from(domain.getEmail_from());
         if(domain.getDateDirtyFlag())
            model.setDate(domain.getDate());
         if(domain.getMail_activity_type_idDirtyFlag())
            model.setMail_activity_type_id(domain.getMail_activity_type_id());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getNeedactionDirtyFlag())
            model.setNeedaction(domain.getNeedaction());
         if(domain.getSubjectDirtyFlag())
            model.setSubject(domain.getSubject());
         if(domain.getRecord_nameDirtyFlag())
            model.setRecord_name(domain.getRecord_name());
         if(domain.getAuthor_avatarDirtyFlag())
            model.setAuthor_avatar(domain.getAuthor_avatar());
         if(domain.getRating_valueDirtyFlag())
            model.setRating_value(domain.getRating_value());
         if(domain.getAuto_deleteDirtyFlag())
            model.setAuto_delete(domain.getAuto_delete());
         if(domain.getAuto_delete_messageDirtyFlag())
            model.setAuto_delete_message(domain.getAuto_delete_message());
         if(domain.getBodyDirtyFlag())
            model.setBody(domain.getBody());
         if(domain.getMail_server_idDirtyFlag())
            model.setMail_server_id(domain.getMail_server_id());
         if(domain.getMessage_idDirtyFlag())
            model.setMessage_id(domain.getMessage_id());
         if(domain.getModelDirtyFlag())
            model.setModel(domain.getModel());
         if(domain.getReply_toDirtyFlag())
            model.setReply_to(domain.getReply_to());
         if(domain.getMessage_typeDirtyFlag())
            model.setMessage_type(domain.getMessage_type());
         if(domain.getStarredDirtyFlag())
            model.setStarred(domain.getStarred());
         if(domain.getIs_logDirtyFlag())
            model.setIs_log(domain.getIs_log());
         if(domain.getNotifyDirtyFlag())
            model.setNotify(domain.getNotify());
         if(domain.getMass_mailing_campaign_idDirtyFlag())
            model.setMass_mailing_campaign_id(domain.getMass_mailing_campaign_id());
         if(domain.getNeed_moderationDirtyFlag())
            model.setNeed_moderation(domain.getNeed_moderation());
         if(domain.getSubtype_idDirtyFlag())
            model.setSubtype_id(domain.getSubtype_id());
         if(domain.getAuthor_idDirtyFlag())
            model.setAuthor_id(domain.getAuthor_id());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getWebsite_publishedDirtyFlag())
            model.setWebsite_published(domain.getWebsite_published());
         if(domain.getMass_mailing_idDirtyFlag())
            model.setMass_mailing_id(domain.getMass_mailing_id());
         if(domain.getRes_idDirtyFlag())
            model.setRes_id(domain.getRes_id());
         if(domain.getTemplate_id_textDirtyFlag())
            model.setTemplate_id_text(domain.getTemplate_id_text());
         if(domain.getMass_mailing_nameDirtyFlag())
            model.setMass_mailing_name(domain.getMass_mailing_name());
         if(domain.getLayoutDirtyFlag())
            model.setLayout(domain.getLayout());
         if(domain.getComposer_idDirtyFlag())
            model.setComposer_id(domain.getComposer_id());
         if(domain.getTemplate_idDirtyFlag())
            model.setTemplate_id(domain.getTemplate_id());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Account_invoice_send convert2Domain( Iaccount_invoice_send model ,Account_invoice_send domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_invoice_send();
        }

        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getRating_idsDirtyFlag())
            domain.setRating_ids(model.getRating_ids());
        if(model.getTracking_value_idsDirtyFlag())
            domain.setTracking_value_ids(model.getTracking_value_ids());
        if(model.getCurrency_idDirtyFlag())
            domain.setCurrency_id(model.getCurrency_id());
        if(model.getMailing_list_idsDirtyFlag())
            domain.setMailing_list_ids(model.getMailing_list_ids());
        if(model.getPrintedDirtyFlag())
            domain.setPrinted(model.getPrinted());
        if(model.getAttachment_idsDirtyFlag())
            domain.setAttachment_ids(model.getAttachment_ids());
        if(model.getInvoice_without_emailDirtyFlag())
            domain.setInvoice_without_email(model.getInvoice_without_email());
        if(model.getNeedaction_partner_idsDirtyFlag())
            domain.setNeedaction_partner_ids(model.getNeedaction_partner_ids());
        if(model.getSnailmail_is_letterDirtyFlag())
            domain.setSnailmail_is_letter(model.getSnailmail_is_letter());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getIs_printDirtyFlag())
            domain.setIs_print(model.getIs_print());
        if(model.getPartner_idDirtyFlag())
            domain.setPartner_id(model.getPartner_id());
        if(model.getSnailmail_costDirtyFlag())
            domain.setSnailmail_cost(model.getSnailmail_cost());
        if(model.getChannel_idsDirtyFlag())
            domain.setChannel_ids(model.getChannel_ids());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getStarred_partner_idsDirtyFlag())
            domain.setStarred_partner_ids(model.getStarred_partner_ids());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getPartner_idsDirtyFlag())
            domain.setPartner_ids(model.getPartner_ids());
        if(model.getChild_idsDirtyFlag())
            domain.setChild_ids(model.getChild_ids());
        if(model.getLetter_idsDirtyFlag())
            domain.setLetter_ids(model.getLetter_ids());
        if(model.getNotification_idsDirtyFlag())
            domain.setNotification_ids(model.getNotification_ids());
        if(model.getInvoice_idsDirtyFlag())
            domain.setInvoice_ids(model.getInvoice_ids());
        if(model.getIs_emailDirtyFlag())
            domain.setIs_email(model.getIs_email());
        if(model.getParent_idDirtyFlag())
            domain.setParent_id(model.getParent_id());
        if(model.getUse_active_domainDirtyFlag())
            domain.setUse_active_domain(model.getUse_active_domain());
        if(model.getModeration_statusDirtyFlag())
            domain.setModeration_status(model.getModeration_status());
        if(model.getModerator_idDirtyFlag())
            domain.setModerator_id(model.getModerator_id());
        if(model.getHas_errorDirtyFlag())
            domain.setHas_error(model.getHas_error());
        if(model.getActive_domainDirtyFlag())
            domain.setActive_domain(model.getActive_domain());
        if(model.getDescriptionDirtyFlag())
            domain.setDescription(model.getDescription());
        if(model.getNo_auto_threadDirtyFlag())
            domain.setNo_auto_thread(model.getNo_auto_thread());
        if(model.getComposition_modeDirtyFlag())
            domain.setComposition_mode(model.getComposition_mode());
        if(model.getAdd_signDirtyFlag())
            domain.setAdd_sign(model.getAdd_sign());
        if(model.getEmail_fromDirtyFlag())
            domain.setEmail_from(model.getEmail_from());
        if(model.getDateDirtyFlag())
            domain.setDate(model.getDate());
        if(model.getMail_activity_type_idDirtyFlag())
            domain.setMail_activity_type_id(model.getMail_activity_type_id());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getNeedactionDirtyFlag())
            domain.setNeedaction(model.getNeedaction());
        if(model.getSubjectDirtyFlag())
            domain.setSubject(model.getSubject());
        if(model.getRecord_nameDirtyFlag())
            domain.setRecord_name(model.getRecord_name());
        if(model.getAuthor_avatarDirtyFlag())
            domain.setAuthor_avatar(model.getAuthor_avatar());
        if(model.getRating_valueDirtyFlag())
            domain.setRating_value(model.getRating_value());
        if(model.getAuto_deleteDirtyFlag())
            domain.setAuto_delete(model.getAuto_delete());
        if(model.getAuto_delete_messageDirtyFlag())
            domain.setAuto_delete_message(model.getAuto_delete_message());
        if(model.getBodyDirtyFlag())
            domain.setBody(model.getBody());
        if(model.getMail_server_idDirtyFlag())
            domain.setMail_server_id(model.getMail_server_id());
        if(model.getMessage_idDirtyFlag())
            domain.setMessage_id(model.getMessage_id());
        if(model.getModelDirtyFlag())
            domain.setModel(model.getModel());
        if(model.getReply_toDirtyFlag())
            domain.setReply_to(model.getReply_to());
        if(model.getMessage_typeDirtyFlag())
            domain.setMessage_type(model.getMessage_type());
        if(model.getStarredDirtyFlag())
            domain.setStarred(model.getStarred());
        if(model.getIs_logDirtyFlag())
            domain.setIs_log(model.getIs_log());
        if(model.getNotifyDirtyFlag())
            domain.setNotify(model.getNotify());
        if(model.getMass_mailing_campaign_idDirtyFlag())
            domain.setMass_mailing_campaign_id(model.getMass_mailing_campaign_id());
        if(model.getNeed_moderationDirtyFlag())
            domain.setNeed_moderation(model.getNeed_moderation());
        if(model.getSubtype_idDirtyFlag())
            domain.setSubtype_id(model.getSubtype_id());
        if(model.getAuthor_idDirtyFlag())
            domain.setAuthor_id(model.getAuthor_id());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getWebsite_publishedDirtyFlag())
            domain.setWebsite_published(model.getWebsite_published());
        if(model.getMass_mailing_idDirtyFlag())
            domain.setMass_mailing_id(model.getMass_mailing_id());
        if(model.getRes_idDirtyFlag())
            domain.setRes_id(model.getRes_id());
        if(model.getTemplate_id_textDirtyFlag())
            domain.setTemplate_id_text(model.getTemplate_id_text());
        if(model.getMass_mailing_nameDirtyFlag())
            domain.setMass_mailing_name(model.getMass_mailing_name());
        if(model.getLayoutDirtyFlag())
            domain.setLayout(model.getLayout());
        if(model.getComposer_idDirtyFlag())
            domain.setComposer_id(model.getComposer_id());
        if(model.getTemplate_idDirtyFlag())
            domain.setTemplate_id(model.getTemplate_id());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
